//
//  date.cpp
//  TikTok
//
//  Created by 吴尚远 on 2022/5/11.
//

#include "date.h"

//检验日期是否正确
bool date::Check_time(int w_year, int w_month, int w_day)
{
   
    bool flag = true;
    
    //判断是否是闰年
    bool flag_year = false;
    if((w_year % 4 == 0 && w_year != 0) )
    {
        //如果是就更新标志
        flag_year = true;
    }
    
    //判断日期是否符合规定
    if(w_year > 0 && w_year <= YEAR)
    {
        switch(w_month)
        {
            case 1:
                if(w_day > 0 && w_day <= 31)
                {
                    break;
                }
                else
                {
                    flag = false;
                }
            case 2:
                //如果是闰年
                if(flag_year == true)
                {
                    if(w_day > 0 && w_day <= 29)
                    {
                        break;
                    }
                    else
                    {
                        flag = false;
                    }
                    break;
                }
                //如果是平年
                else
                {
                    if(w_day > 0 && w_day <= 28)
                    {
                        break;
                    }
                    else
                    {
                        flag = false;
                    }
                    break;
                }
            case 3:
                if(w_day > 0 && w_day <= 31)
                {
                    break;
                }
                else
                {
                    flag = false;
                }
                break;
            case 4:
                if(w_day > 0 && w_day <= 30)
                {
                    break;
                }
                else
                {
                    flag = false;
                }
                break;
            case 5:
                if(w_day > 0 && w_day <= 31)
                {
                    break;
                }
                else
                {
                    flag = false;
                }
                break;
            case 6:
                if(w_day > 0 && w_day <= 30)
                {
                    break;
                }
                else
                {
                    flag = false;
                }
                break;
            case 7:
                if(w_day > 0 && w_day <= 31)
                {
                    break;
                }
                else
                {
                    flag = false;
                }
                break;
            case 8:
                if(w_day > 0 && w_day <= 31)
                {
                    break;
                }
                else
                {
                    flag = false;
                }
                break;
            case 9:
                if(w_day > 0 && w_day <= 30)
                {
                    break;
                }
                else
                {
                    flag = false;
                }
                break;
            case 10:
                if(w_day > 0 && w_day <= 31)
                {
                    break;
                }
                else
                {
                    flag = false;
                }
                break;
            case 11:
                if(w_day > 0 && w_day <= 30)
                {
                    break;
                }
                else
                {
                    flag = false;
                }
                break;
            case 12:
                if(w_day > 0 && w_day <= 31)
                {
                    break;
                }
                else
                {
                    flag = false;
                }
                break;
            default:
                flag = false;
                break;
                
                
            
       }
    }
    else
    {
        flag = false;
    }

    return flag;
}
